package com.wenjie.controller;


import com.wenjie.original.entity.Box;
import com.wenjie.original.entity.Order;
import com.wenjie.original.entity.Sku;
import com.wenjie.original.entity.User;
import com.wenjie.original.service.IBoxService;
import com.wenjie.original.service.IOrderService;
import com.wenjie.original.service.ISkuService;
import com.wenjie.original.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api("基础数据查询管理")
@RestController
@RequestMapping("/api/base")
public class BaseDataController {

    @Autowired
    private IOrderService orderService;

    @Autowired
    private IBoxService boxService;

    @Autowired
    private ISkuService skuService;

    @Autowired
    private IUserService userService;

    @ApiOperation("查询接口")
    @PostMapping("/list")
    public Map<String, List> list(@RequestBody @Validated List<String> strs) {
        Map<String, List> res = new HashMap<>();
        for (String str : strs) {
            switchObj(str, res);
        }
        return res;
    }

    private void switchObj(String str, Map<String, List> map) {
        switch (str) {

            case "order": { // 订单
                List<Order> list = orderService.list();
                map.put("order", list);
                return;
            }


            case "box": { // 箱子
                List<Box> list = boxService.list();
                map.put("box", list);
                return;
            }

            case "sku": { // 商品
                List<Sku> list = skuService.list();
                map.put("sku", list);
                return;
            }

            case "user": { // 用户信息
                List<User> list = userService.list();
                map.put("user", list);
                return;
            }


        }
    }


}
